package com.xianggu.springBoot;

import com.xianggu.springBoot.annotation.XiangGuConditionOnClass;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @author chengjy
 * @date 2025/3/5
 */
public class XiangGuCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 获取类加载器
        Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(XiangGuConditionOnClass.class.getName());
        String path = (String) annotationAttributes.get("value");
        try {
            context.getClassLoader().loadClass(path);
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
    }
}
